package com.wayhome.springframework.beans.factory.support;

import com.wayhome.springframework.beans.BeanException;
import com.wayhome.springframework.beans.factory.config.BeanDefinition;

/**
 * 可以自动装配的抽象beanFactory
 */
public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory{

    @Override
    protected Object createBean(String beanName, BeanDefinition beanDefinition) throws BeanException {
        Object bean = null;
        try {
            bean = beanDefinition.getBeanClass().newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw  new BeanException("instantiation of bean failed", e);
        }
        addSingleton(beanName, bean);
        return bean;
    }
}
